#!/usr/bin/env python
# -*- encoding: utf-8 -*-
"""
@Introduce :
@File      : tasks.py
@Time      : 2023/9/28 17:16
@Author    : toby
"""
from __future__ import absolute_import
import time
import logging

from pytest_package.pytest_main import StartRun
from utilspakage.django_email import YaGmail

from  django32_celery.celery import app

logger = logging.getLogger(__name__)

# # name表示设置任务的名称，如果不填写，则默认使用函数名做为任务名
# 定义的两个异步函数
@app.task
def send_sms():
    for i in range(1,10):
        time.sleep(1)
        logger.info("send_sms:{}".format(i))
        print(f"发送短信!!!{i}")
    return "Send_sms OK  task !"


@app.task
def api_test():
    StartRun().runcase()
    return "Interface test start run task ,执行完成后自动发送邮件..."

@app.task
def crontab_job():
    StartRun().runcase()
    return 'Crontab test task 定时任务执行完成...'


@app.task
def choosescript():
    report_path=StartRun(True).runcase()

    return report_path


@app.task
def send_sms2():
    for j in range(1,10):
        print(f"发送短信任务2!!!!!!{j}")
        logger.info("send_sms:{}".format(j))
        time.sleep(1)

    sender = 'hejunwang01@126.com'
    receivers = ['287619892@qq.com', 'hejunwang02@126.com']
    sendemail = YaGmail(sender, receivers)
    sendemail.send()
    return "OK"

@app.task
def devicemanager(x):
    for j in range(1,x):
        print(f"devicemanager!!!!!!{j}")
        time.sleep(1)
    return " Task Devicemanager OK"




